<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="container">
  </div>
  <script>
    const con = document.getElementById('container');
    con.innerHTML = '<p>123</p>';
    let p1 = con.getElementsByTagName('p')[0]
    // let p2
    // setTimeout(() => {
    //   con.innerHTML = '<p>123</p>';
    //   p2 = con.getElementsByTagName('p')[0]
    //   console.log(p1, p2)
    //   // 验证了innerHTML 是会重新创建dom的（即使dom元素相同）
    //   console.log(p1 === p2) // false
    // }, 3000)


    function sleep(time) {
      return new Promise((resolve) => {
        setTimeout(resolve, time)
      })
    }
    function* gen() {
      yield 123
      yield sleep(2000)
      yield 'qwd'
      yield sleep(2000)
      yield ' sad'
    }

    (async () => {
      for await (const value of gen()) {
        if(value)
        // 验证了虽然dom每次都替换，但是视觉上dom是连续的
          con.innerHTML += `<span>${value}</span>`
      }
    })()
    
  </script>
</body>
</html>